#include "odbc/connection.hpp"
#include "odbc/environment.hpp"
#include "odbc/odbc_error.hpp"
#include <boost/test/auto_unit_test.hpp>

namespace
{


#define ODBCTEST_CHECK_SUCCESSFUL_CONNECTION( ENV_OBJ, DSN_NAME, TIMEOUT) \
	{ \
		std::string connStr = "DSN="; \
		connStr += DSN_NAME; \
		try \
		{ \
			connection conn( ENV_OBJ, connStr, TIMEOUT); \
		} \
		catch( odbc_error& e) \
		{ \
			BOOST_CHECK_MESSAGE( false, "Error connecting using " + connStr + ". Details: " + e.what()); \
		} \
	}

using namespace odbc;

BOOST_AUTO_TEST_CASE( testConnection)
{
	environment env(3);
	ODBCTEST_CHECK_SUCCESSFUL_CONNECTION( env, "mysql_odbc_tests", 10);
	BOOST_CHECK_THROW( connection( env, "Invalid connection string", 10), odbc_error);
}

} // namespace
